import { Injectable } from '@nestjs/common';
import { CacheService } from '@/servers/redis/cache/cache.service';

@Injectable()
export class UserinfoService {

    constructor(
        private cacheService: CacheService
    ) {

    }

    /**
     * 获取用户信息
     */
    async getUser(token) {
        let user = await this.cacheService.get(token);
        return user;
    }

    /**
     * 获取引物token
     */
    async getInwuToken(token) {
        let user = await this.getUser(token);
        if (user && user['inwu']) {
            return user['inwu'].token;
        } else {
            return null;
        }
    }

    /**
     * 获取引物刷新token
     */
    async getInwuRefreshToken(token) {
        let user = await this.getUser(token);
        if (user && user['inwu']) {
            return user['inwu'].refreshToken;
        } else {
            return null;
        }
    }
}
